<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品详情</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <style>
        #shopping_cart {
            position: fixed;
            z-index: 99;
            background: rgba(0, 0, 0, .6);
            width: 3rem;
            right: .4rem;
            bottom: 10rem;
            color: white;
            text-align: center;
            border-radius: .3rem;
            padding: .3rem 0;
            font-size: .7rem;
        }

        #shopping_cart img {
            width: 50%;
            margin: 0 auto;
        }

        .aui-info {
            width: 100%;
            padding: 0;
        }

        .aui-card-list {
            margin: 0;
            border-bottom: .5rem solid #F7F7F7
        }

        .aui-card-list-header,
        .aui-card-list-footer {
            padding: .5rem .75rem 0;
        }

        .aui-tab-item {
            width: auto;
            color: #e51c23;
            border-bottom: 2px solid #e51c23;
            padding: 0 .75rem;
        }

        .aui-tab {
            border-bottom: 1px solid #F7F7F7;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 购物车图标 -->
        <div id="shopping_cart" @click="openWin('shopping_cart')">
            <img src="../../../image/icon/gouwuche.png" alt="">
            <div>购物车</div>
        </div>
        <div class="aui-content">
            <div class="aui-card-list">
                <div class="aui-card-list-content">
                    <img :src="detail.pic" />
                </div>
                <div class="aui-card-list-header">
                    {{detail.name}}
                </div>
                <div class="aui-card-list-footer">
                    <div class="aui-info">
                        <div class="aui-info-item aui-text-danger aui-font-size-18">
                            ￥{{detail.price}}
                        </div>
                        <div class="aui-info-item">{{detail.buy}}人付款</div>
                    </div>
                </div>
            </div>
            <div class="aui-tab">
                <div class="aui-tab-item aui-font-size-18">图文详情</div>
            </div>
            <div class="aui-content-padded" v-html="detail.content">
            </div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();

        vm.init();
    }
    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            detail: {}
        },
        methods: {
            init() {
                this.userInfo = get_local('userInfo');
                this.getDetail();
            },
            getDetail() {
                var self = this;
                _ajax(Config.api.MallDetail, {
                    gid: api.pageParam.id,
                    user_id: self.userInfo.user_id
                }, function(res) {
                    if (res.code === 200) {
                        self.detail = res.data;
                        self.updateCollectStatus(self.detail.is_collect);
                    }
                });
            },
            addCar() {
                _ajax(Config.api.CartAdd, {
                    user_id: this.userInfo.user_id,
                    mid: api.pageParam.mid,
                    gid: api.pageParam.id
                }, function(res) {
                    if (res.code === 200) {
                        $toast('添加成功,在购物车等亲哦！');
                    } else {
                        $toast(res.code + '添加失败！请稍后再试');
                    }

                })
            },
            collect() {
                var self = this;
                _ajax(Config.api.ShopGoodscollect, {
                    data_id: api.pageParam.id,
                    user_id: self.userInfo.user_id
                }, function(res) {
                    if (res.code === 200) {
                        $toast('收藏成功');
                        self.updateCollectStatus(1);
                    }
                })
            },
            updateCollectStatus(status) {
                api.execScript({
                    script: 'isCollect(' + status + ')'
                });
            },
            openWin(name, param = {}) {
                var winInfo = {
                    shopping_cart: {
                        name: 'shopping_cart_win',
                        url: './shopping_cart_win.html',
                        param: param
                    }
                };
                open_w(winInfo[name].name, winInfo[name].url, winInfo[name].param, true, true);
            },
            shop() {
                open_w('shop', './shop_win.html', {
                    name: this.detail.shop_name,
                    shop_id: this.detail.mid
                }, true, true);
            }
        }
    });

    function collect() {
        vm.collect();
    }

    function addCar() {
        vm.addCar();
    }

    function shop() {
        vm.shop();
    }
</script>

</html>
